﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Odbc;
using System.Linq;
using System.Text;

namespace TestConnect2Sybase
{
    class Program
    {
        static void Main(string[] args)
        {

            string strconn = "DSN=10.0.1.240";
            OdbcConnection connection = new OdbcConnection(strconn);
            OdbcDataAdapter da = new OdbcDataAdapter(@"SELECT egv.MC_OBJECT as 'object',egv.MC_OBJECT_CLASS as 'type',
egv.SEVERITY as 'level',egv.MC_ARRIVAL_TIME as 'time',
egv.MSG as 'content' FROM EG_EVENT_VIEW egv where egv.STATUS = 'OPEN' AND egv.SEVERITY in ('MAJOR','CRITICAL') order by 'time' desc, 'level'", connection);
            DataTable dataTable = new DataTable();

            try
            {
                da.Fill(dataTable);
                Console.WriteLine(dataTable.Rows.Count);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                connection.Close();
            }

        //    try
        //    {

        //        string strconn = "DSN=10.0.1.240";

        //        OdbcConnection SybaseConn = new OdbcConnection(strconn);

        //        OdbcDataAdapter da = new OdbcDataAdapter("select count(*) from eg_event", SybaseConn);

        //        DataTable dt = new DataTable();

        //        da.Fill(dt);
        //        Console.WriteLine("ok" + dt.Rows.Count.ToString());
        //    }
        //    catch(Exception ex)
        //    {
        //        Console.WriteLine(ex.ToString());

        //    }
            Console.ReadKey();
        }
    }
}
